package ltd.trackan.messagecenter.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import ltd.trackan.messagecenter.common.ValueCommon;
import ltd.trackan.messagecenter.model.entity.Messagechannel;
import ltd.trackan.messagecenter.service.MessageChannelService;
import ltd.trackan.messagecenter.mapper.MessagechannelMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @author wxa
 * @description 针对表【messagechannel(消息渠道表)】的数据库操作Service实现
 * @createDate 2025-03-11 11:07:46
 */
@Service
@Slf4j
public class MessageChannelServiceImpl extends ServiceImpl<MessagechannelMapper, Messagechannel>
        implements MessageChannelService {
    
    @Override
    public void updateAllMessageChannel() {
        try {
            ValueCommon.JD_CHANNEL_MAP.clear();
            this.baseMapper.selectList(null).forEach(messagechannel -> {
                try {
                    HashMap<String, String> value = new HashMap<>();
                    // 将Object转换为String
                    value.put(messagechannel.getName(), messagechannel.getJson());
                    ValueCommon.JD_CHANNEL_MAP.put(messagechannel.getUId(), value);
                } catch (Exception e) {
                    log.error("该id：{}的渠道json转换错误：{}", messagechannel.getUId(), e.getMessage());
                }
            });
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }
}




